package com.wetao.module_user.dialog;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.appcompat.widget.AppCompatTextView;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.flexbox.AlignItems;
import com.google.android.flexbox.FlexDirection;
import com.google.android.flexbox.FlexWrap;
import com.google.android.flexbox.FlexboxLayout;
import com.google.android.flexbox.FlexboxLayoutManager;
import com.google.android.flexbox.JustifyContent;
import com.wetao.lib_common.bean.response.AreaSchoolInfo;
import com.wetao.lib_common.bean.response.SchoolClassInfo;
import com.wetao.lib_common.bean.response.SchoolGradeInfo;
import com.wetao.lib_common.utils.LogUtils;
import com.wetao.lib_common.utils.ToastUtil;
import com.wetao.lib_common.view.OnMultiClickListener;
import com.wetao.lib_common.view.dialog.CustomDialog;
import com.wetao.lib_common.view.dialog.OnCustomDialogItemClickListener;
import com.wetao.module_user.R;
import com.wetao.module_user.adapter.SchoolClassRecyclerAdapter;
import com.wetao.module_user.adapter.SchoolRecyclerAdapter;

import java.util.List;

public class DialogSwitchSchool {
    public static final int DIALOG_CLASS_ADMIN_UPDATE = 1;
    public static final int DIALOG_CLASS_COACH_UPDATE = 2;
    public static final int DIALOG_CLASS_COACH_JOIN = 3;

    CustomDialog mDialogSwitchAddClass;

    String title, schoolName, gradeName, className;
    Integer mCurrClassId, mCurrGradeId, type, mCurrSchoolId = null;
    Context context;

    SchoolRecyclerAdapter mSchoolRecyclerAdapter;
    SchoolClassRecyclerAdapter mClassRecyclerAdapter, mClassAdminRecyclerAdapter;
    RecyclerView mSchoolList, mClassList;

    private volatile int areaType = 1;
    private StringBuilder schoolAllName = new StringBuilder();

    private SchoolGradeInfo mCurrSchoolGradeInfo;
    private SchoolClassInfo mCurrGradeClassInfo, mCurrGradeClassAdminInfo;

/*
    public DialogSwitchSchool(Context context, String title, String schoolName, String gradeName, String className, Integer classId, int type) {
        this.title = title;
        this.schoolName = schoolName;
        this.gradeName = gradeName;
        this.className = className;
        this.mCurrClassId = classId;
        this.type = type;
        this.context = context;
        if(null == mDialogSwitchAddClass) {
            mDialogSwitchAddClass = new CustomDialog(context,
                    R.layout.user_dialog_class_update_or_add,
                    new int[]{R.id.ib_delete, R.id.bt_cancel, R.id.bt_ok, R.id.tv_titile,
                            R.id.tv_school_all_name, R.id.tv_grade_all_name, R.id.tv_class_all_name},
                    0,
                    false,
                    true,
                    Gravity.CENTER);
            setListern(type);
        }
    }

    public void update(Context context, String title, String schoolName, String gradeName, String className, Integer classId, int type) {
        this.title = title;
        this.schoolName = schoolName;
        this.gradeName = gradeName;
        this.className = className;
        this.mCurrClassId = classId;
        this.type = type;
        this.context = context;

        if(null == mDialogSwitchAddClass) {
            mDialogSwitchAddClass = new CustomDialog(context,
                    R.layout.user_dialog_class_update_or_add,
                    new int[]{R.id.ib_delete, R.id.bt_cancel, R.id.bt_ok, R.id.tv_titile,
                            R.id.tv_school_all_name, R.id.tv_grade_all_name, R.id.tv_class_all_name},
                    0,
                    false,
                    true,
                    Gravity.CENTER);
            setListern(type);
        }
    }
*/
    public DialogSwitchSchool(Context context, String title, String schoolName, Integer schoolId, String gradeName, Integer gradeId, String className, Integer classId, int type) {
        this.title = title;
        this.schoolName = schoolName;
        this.gradeName = gradeName;
        this.className = className;
        this.mCurrClassId = classId;
        this.mCurrGradeId = gradeId;
        this.mCurrSchoolId = schoolId;
        this.type = type;
        this.context = context;
        if(null == mDialogSwitchAddClass) {
            mDialogSwitchAddClass = new CustomDialog(context,
                    R.layout.user_dialog_class_update_or_add,
                    new int[]{R.id.ib_delete, R.id.bt_cancel, R.id.bt_ok, R.id.tv_titile,
                            R.id.tv_school_all_name, R.id.tv_grade_all_name, R.id.tv_class_all_name},
                    0,
                    false,
                    true,
                    Gravity.CENTER);
            setListern(type);
        }
    }

    public void update(Context context, String title, String schoolName, Integer schoolId, String gradeName, Integer gradeId,String className, Integer classId, int type) {
        this.title = title;
        this.schoolName = schoolName;
        this.gradeName = gradeName;
        this.className = className;
        this.mCurrClassId = classId;
        this.mCurrGradeId = gradeId;
        this.mCurrSchoolId = schoolId;
        this.type = type;
        this.context = context;

        if(null == mDialogSwitchAddClass) {
            mDialogSwitchAddClass = new CustomDialog(context,
                    R.layout.user_dialog_class_update_or_add,
                    new int[]{R.id.ib_delete, R.id.bt_cancel, R.id.bt_ok, R.id.tv_titile,
                            R.id.tv_school_all_name, R.id.tv_grade_all_name, R.id.tv_class_all_name},
                    0,
                    false,
                    true,
                    Gravity.CENTER);
            setListern(type);
        }
    }


    public void show(){
        if(null != mDialogSwitchAddClass) {
            mDialogSwitchAddClass.show();

            final List<View> viewList = mDialogSwitchAddClass.getViews();
            if (null != viewList) {
                ((AppCompatTextView) viewList.get(3)).setText(title);
                ((AppCompatTextView) viewList.get(4)).setText(schoolName);
                ((AppCompatTextView) viewList.get(5)).setText(gradeName);
                ((AppCompatTextView) viewList.get(6)).setText(className);
            }
        }
    }

    public void displaySchool(List<AreaSchoolInfo> areaSchoolInfos){
        if(null != mDialogSwitchAddClass) {
            mDialogSwitchAddClass.findViewById(R.id.cl_school_choice).setVisibility(View.VISIBLE);
            displaySchoolInfo(areaSchoolInfos, new OnListenFlexLayout() {
                @Override
                public void onListenFlexLayout(Object info) {
                    AreaSchoolInfo areaSchoolInfo = (AreaSchoolInfo)info;
                    if (1 == areaSchoolInfo.getIsSchool()) {
                        schoolAllName.append(areaSchoolInfo.getName());
                        mCurrSchoolId = areaSchoolInfo.getId();
                        areaType = 1;
                        mDialogSwitchAddClass.findViewById(R.id.cl_school_choice).setVisibility(View.GONE);
                        /*mDialogSwitchAddClass.findViewById(R.id.tv_grade_all_name).setVisibility(View.VISIBLE);
                        mDialogSwitchAddClass.findViewById(R.id.tv_class_all_name).setVisibility(View.VISIBLE);*/
                        AppCompatTextView tv = (AppCompatTextView) mDialogSwitchAddClass.findViewById(R.id.tv_school_all_name);
                        tv.setText(schoolAllName.toString());
                        tv.setCompoundDrawablesWithIntrinsicBounds(
                                null, null, context.getResources().getDrawable(R.drawable.common_arrow_down), null);

                        mCurrSchoolGradeInfo = null;
                        ((AppCompatTextView) mDialogSwitchAddClass.findViewById(R.id.tv_grade_all_name)).setText("");
                        mCurrGradeClassInfo = null;
                        ((AppCompatTextView) mDialogSwitchAddClass.findViewById(R.id.tv_class_all_name)).setText("");

                        return;
                    }
                    schoolAllName.append(areaSchoolInfo.getName()).append("/");
                    areaType++;
                    setSchoolTitle(mDialogSwitchAddClass.findViewById(R.id.tv_school_choice_tip), areaType);
                    if(null != onListenDataReq) {
                        onListenDataReq.onListenAreaReq(areaType, areaSchoolInfo.getId());
                    }
                   // mSchoolRecyclerAdapter = null;
                }
            });
        } else {
            LogUtils.i( "mDialogSwitchAddClass == null");
        }
    }

    public void displayGrade(List<SchoolGradeInfo> schoolGradeInfoList) {
        if(null != mDialogSwitchAddClass) {
            displayGradeInfo(schoolGradeInfoList, (FlexboxLayout) mDialogSwitchAddClass.findViewById(R.id.fl_grade_choice), new OnListenFlexLayout() {
                @Override
                public void onListenFlexLayout(Object info) {
                    displayGradeDetail((SchoolGradeInfo)info);

                    /*mDialogSwitchAddClass.findViewById(R.id.cl_grade_choice).setVisibility(View.GONE);
                    AppCompatTextView tv = (AppCompatTextView) mDialogSwitchAddClass.findViewById(R.id.tv_grade_all_name);
                    tv.setText(mCurrSchoolGradeInfo.getLabel());
                    tv.setCompoundDrawablesWithIntrinsicBounds(
                            null, null, context.getResources().getDrawable(R.drawable.common_arrow_down), null);*/
                }
            });
        } else {
            LogUtils.i( "mDialogSwitchAddClass == null");
        }
    }


    private void displayGradeDetail(SchoolGradeInfo parent){
        displayGradeInfo(parent.getChildren(), (FlexboxLayout) mDialogSwitchAddClass.findViewById(R.id.fl_grade_choice), new OnListenFlexLayout() {
            @Override
            public void onListenFlexLayout(Object info) {
                mCurrSchoolGradeInfo = (SchoolGradeInfo)info;

                mCurrGradeId = mCurrSchoolGradeInfo.getId();

                mDialogSwitchAddClass.findViewById(R.id.cl_grade_choice).setVisibility(View.GONE);
                AppCompatTextView tv = (AppCompatTextView) mDialogSwitchAddClass.findViewById(R.id.tv_grade_all_name);
                tv.setText(mCurrSchoolGradeInfo.getLabel());
                tv.setCompoundDrawablesWithIntrinsicBounds(
                        null, null, context.getResources().getDrawable(R.drawable.common_arrow_down), null);

                ((AppCompatTextView) mDialogSwitchAddClass.findViewById(R.id.tv_class_all_name)).setText("");
                mCurrGradeClassInfo = null;
            }
        });
    }

    public void displayClass(List<SchoolClassInfo> schoolClassInfoList) {
        if(null != mDialogSwitchAddClass) {
            displayClassInfo(schoolClassInfoList, new OnListenFlexLayout() {
                @Override
                public void onListenFlexLayout(Object info) {
                    mCurrGradeClassInfo = (SchoolClassInfo)info;

                    mDialogSwitchAddClass.findViewById(R.id.cl_class_choice).setVisibility(View.GONE);
                    AppCompatTextView tv = (AppCompatTextView) mDialogSwitchAddClass.findViewById(R.id.tv_class_all_name);
                    tv.setText(mCurrGradeClassInfo.getClassName());
                    tv.setCompoundDrawablesWithIntrinsicBounds(
                            null, null, context.getResources().getDrawable(R.drawable.common_arrow_down), null);
                }
            });
        } else {
            LogUtils.i( "mDialogSwitchAddClass == null");
        }
    }

    public void displayAdminClass(List<SchoolClassInfo> schoolClassAdminInfoList) {
        if(null != mDialogSwitchAddClass) {
            displayClassAdminInfo(schoolClassAdminInfoList, new OnListenFlexLayout() {
                @Override
                public void onListenFlexLayout(Object info) {
                    mCurrGradeClassAdminInfo = (SchoolClassInfo)info;

                    mDialogSwitchAddClass.findViewById(R.id.cl_class_choice).setVisibility(View.GONE);
                    AppCompatTextView tv = (AppCompatTextView) mDialogSwitchAddClass.findViewById(R.id.tv_class_all_name);
                    tv.setText(mCurrGradeClassAdminInfo.getClassName());
                    tv.setCompoundDrawablesWithIntrinsicBounds(
                            null, null, context.getResources().getDrawable(R.drawable.common_arrow_down), null);
                }
            });
        } else {
            LogUtils.i( "mDialogSwitchAddClass == null");
        }
    }


    public void deleteDialogSwitchAddClass(){
        if(null != mSchoolRecyclerAdapter) {
            mSchoolRecyclerAdapter = null;
        }
        if(null != mClassRecyclerAdapter) {
            mClassRecyclerAdapter = null;
        }
        if(null != mDialogSwitchAddClass) {
            mDialogSwitchAddClass.dismiss();
            mDialogSwitchAddClass = null;
        }
    }

    private void setListern(int type){
        mDialogSwitchAddClass.setOnDialogItemClickListener(new OnCustomDialogItemClickListener() {
            @Override
            public void OnCustomDialogItemClick(CustomDialog dialog, View view) {
                int id = view.getId();
                if (id == R.id.ib_delete) {
                    deleteDialogSwitchAddClass();
                } else if (id == R.id.bt_cancel) {
                    deleteDialogSwitchAddClass();
                } else if (id == R.id.bt_ok) {
                    if(null == mCurrSchoolId) {
                        ToastUtil.initToast("请先选择学校");
                        return;
                    }
                    /*if(null == mCurrSchoolGradeInfo) {
                        ToastUtil.initToast("请先选择年级");
                        return;
                    }*/
                    switch (type) {
                        case DIALOG_CLASS_ADMIN_UPDATE:
                            if(null != mCurrGradeClassAdminInfo) {
                                if(null != onListenDataReq) {
                                    onListenDataReq.onListenClassAdminUpdateReq(mCurrGradeClassAdminInfo.getClassId());
                                }
                            }else{
                                ToastUtil.initToast("请先选择班级");
                            }
                            break;
                        case DIALOG_CLASS_COACH_UPDATE:
                            if(null != mCurrGradeClassInfo) {
                                if(null != onListenDataReq) {
                                    onListenDataReq.onListenClassCoachUpdateReq(mCurrGradeClassInfo.getClassId(), mCurrClassId);
                                }
                            }else{
                                ToastUtil.initToast("请先选择班级");
                            }
                            break;
                        case DIALOG_CLASS_COACH_JOIN:
                            if(null != mCurrGradeClassInfo) {
                                if(null != onListenDataReq) {
                                    onListenDataReq.onListenClassCoachJoinReq(mCurrGradeClassInfo.getClassId());
                                }
                            }else{
                                ToastUtil.initToast("请先选择班级");
                            }
                            break;
                        default:
                            throw new IllegalStateException("Unexpected value: " + type);
                    }
                } else if (id == R.id.tv_school_all_name) {
                    if(View.VISIBLE != mDialogSwitchAddClass.findViewById(R.id.cl_school_choice).getVisibility()) {
                        mDialogSwitchAddClass.findViewById(R.id.cl_school_choice).setVisibility(View.VISIBLE);
                        mDialogSwitchAddClass.findViewById(R.id.cl_grade_choice).setVisibility(View.INVISIBLE);
                        mDialogSwitchAddClass.findViewById(R.id.cl_class_choice).setVisibility(View.INVISIBLE);
                        ((AppCompatTextView) view).setCompoundDrawablesWithIntrinsicBounds(
                                null, null, context.getResources().getDrawable(R.drawable.common_arrow_up), null);
                        areaType = 1;
                        schoolAllName.setLength(0);
                        setSchoolTitle(mDialogSwitchAddClass.findViewById(R.id.tv_school_choice_tip), areaType);
                        if(null != onListenDataReq) {
                            onListenDataReq.onListenAreaReq(areaType);
                        }
                    } else {
                        mDialogSwitchAddClass.findViewById(R.id.cl_school_choice).setVisibility(View.GONE);
                        ((AppCompatTextView) view).setCompoundDrawablesWithIntrinsicBounds(
                                null, null, context.getResources().getDrawable(R.drawable.common_arrow_down), null);
                        /*mDialogSwitchAddClass.findViewById(R.id.tv_grade_all_name).setVisibility(View.VISIBLE);
                        mDialogSwitchAddClass.findViewById(R.id.tv_class_all_name).setVisibility(View.VISIBLE);*/
                    }
                } else if (id == R.id.tv_grade_all_name) {
                    if(View.VISIBLE != mDialogSwitchAddClass.findViewById(R.id.cl_grade_choice).getVisibility()) {
                        mDialogSwitchAddClass.findViewById(R.id.cl_grade_choice).setVisibility(View.VISIBLE);
                        mDialogSwitchAddClass.findViewById(R.id.cl_school_choice).setVisibility(View.INVISIBLE);
                        mDialogSwitchAddClass.findViewById(R.id.cl_class_choice).setVisibility(View.INVISIBLE);
                        ((AppCompatTextView) view).setCompoundDrawablesWithIntrinsicBounds(
                                null, null, context.getResources().getDrawable(R.drawable.common_arrow_up), null);
                        if(null != mCurrSchoolId) {
                            if(null != onListenDataReq) {
                                onListenDataReq.onListenSchoolGradeReq(mCurrSchoolId);
                            }
                        }else{
                            ToastUtil.initToast("请先选择学校!");
                        }
                    } else {
                        mDialogSwitchAddClass.findViewById(R.id.cl_grade_choice).setVisibility(View.GONE);
                        //mDialogSwitchAddClass.findViewById(R.id.tv_class_all_name).setVisibility(View.VISIBLE);
                        ((AppCompatTextView) view).setCompoundDrawablesWithIntrinsicBounds(
                                null, null, context.getResources().getDrawable(R.drawable.common_arrow_down), null);
                    }
                } else if (id == R.id.tv_class_all_name) {
                    if(View.VISIBLE != mDialogSwitchAddClass.findViewById(R.id.cl_class_choice).getVisibility()) {
                        mDialogSwitchAddClass.findViewById(R.id.cl_class_choice).setVisibility(View.VISIBLE);
                        mDialogSwitchAddClass.findViewById(R.id.cl_grade_choice).setVisibility(View.INVISIBLE);
                        mDialogSwitchAddClass.findViewById(R.id.cl_school_choice).setVisibility(View.INVISIBLE);
                        ((AppCompatTextView) view).setCompoundDrawablesWithIntrinsicBounds(
                                null, null, context.getResources().getDrawable(R.drawable.common_arrow_up), null);
                        if(null != mCurrSchoolId) {
                            /*displayClassInfo(mCurrSchoolGradeInfo.getChildren(), (FlexboxLayout) mDialogSwitchAddClass.findViewById(R.id.fl_class_choice), new OnListenFlexLayout() {
                                @Override
                                public void onListenFlexLayout(Object info) {
                                    mCurrDetailGradeInfo = (SchoolGradeInfo.Grade)info;

                                    mDialogSwitchAddClass.findViewById(R.id.cl_class_choice).setVisibility(View.GONE);
                                    AppCompatTextView tv = (AppCompatTextView) mDialogSwitchAddClass.findViewById(R.id.tv_class_all_name);
                                    tv.setText(mCurrDetailGradeInfo.getLabel());
                                    tv.setCompoundDrawablesWithIntrinsicBounds(
                                            null, null, context.getResources().getDrawable(R.drawable.common_arrow_down), null);
                                }
                            });*/
                            /*if(null != onListenDataReq && null != mCurrSchoolGradeInfo) {
                                if(DIALOG_CLASS_ADMIN_UPDATE == type) {
                                    onListenDataReq.onListenGradeClassAdminReq(mCurrSchoolId, mCurrSchoolGradeInfo.getId());
                                } else {
                                    onListenDataReq.onListenGradeClassReq(mCurrSchoolId, mCurrSchoolGradeInfo.getId());
                                }*/
                            if(null != onListenDataReq && null != mCurrGradeId) {
                                if(DIALOG_CLASS_ADMIN_UPDATE == type) {
                                    onListenDataReq.onListenGradeClassAdminReq(mCurrSchoolId, mCurrGradeId);
                                } else {
                                    onListenDataReq.onListenGradeClassReq(mCurrSchoolId, mCurrGradeId);
                                }
                            }else {
                                ToastUtil.initToast("请先选择年级!");
                            }
                        } else {
                            ToastUtil.initToast("请先选择学校!");
                        }
                    } else {
                        mDialogSwitchAddClass.findViewById(R.id.cl_class_choice).setVisibility(View.GONE);
                        ((AppCompatTextView) view).setCompoundDrawablesWithIntrinsicBounds(
                                null, null, context.getResources().getDrawable(R.drawable.common_arrow_down), null);
                    }
                }
            }
        });
    }


    void setSchoolTitle(AppCompatTextView tv, int areaType){
        switch (areaType) {
            case 1:
                tv.setText(R.string.user_choice_province_str);
                break;
            case 2:
                tv.setText(R.string.user_choice_city_str);
                break;
            case 3:
                tv.setText(R.string.user_choice_area_str);
                break;
            case 4:
                tv.setText(R.string.user_choice_school_str);
                break;
        }

    }



    private void displaySchoolInfo(List<AreaSchoolInfo> areaSchoolInfos, OnListenFlexLayout onListenFlexLayout) {
        FlexboxLayoutManager manager = new FlexboxLayoutManager();
        //设置主轴排列方式
        manager.setFlexDirection(FlexDirection.ROW);
        manager.setAlignItems(AlignItems.STRETCH);
        manager.setJustifyContent(JustifyContent.FLEX_START);
        //设置是否换行
        manager.setFlexWrap(FlexWrap.WRAP);

        mSchoolList = mDialogSwitchAddClass.findViewById(R.id.fl_school_choice);
        mSchoolList.setLayoutManager(manager);

        if(null == mSchoolRecyclerAdapter) {
            mSchoolRecyclerAdapter = new SchoolRecyclerAdapter(context, areaSchoolInfos);
            mSchoolList.setItemAnimator(new DefaultItemAnimator());
            mSchoolList.setAdapter(mSchoolRecyclerAdapter);
        } else {
            mSchoolRecyclerAdapter.setData(areaSchoolInfos);
            mSchoolRecyclerAdapter.notifyDataSetChanged();
        }
        mSchoolRecyclerAdapter.setOnItemClickListener(new SchoolRecyclerAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position, List<AreaSchoolInfo> listModel) {
                if(null != onListenFlexLayout) {
                    onListenFlexLayout.onListenFlexLayout(listModel.get(position));
                }
            }
        });
    }

    private void displayGradeInfo(List<SchoolGradeInfo> schoolGradeInfos, FlexboxLayout flexBoxLayout, OnListenFlexLayout onListenFlexLayout) {
        flexBoxLayout.removeAllViews();
        for (int i = 0; i < schoolGradeInfos.size(); i++) {
            SchoolGradeInfo item = schoolGradeInfos.get(i);
            TextView textView = new TextView(context);
            textView.setText(item.getLabel());
            textView.setTextSize(18.0f);
            textView.setTextColor(context.getResources().getColor(R.color.common_theme));
            textView.setTag(i);
            textView.setPadding(10, 0, 10, 0);
            // textView.setBackgroundResource(R.drawable.bg_round_button_selector);
            textView.setOnClickListener(new OnMultiClickListener() {
                @Override
                public void onMultiClick(View v) {
                    int index = (int)v.getTag();
                    if(null != onListenFlexLayout) {
                        onListenFlexLayout.onListenFlexLayout(schoolGradeInfos.get(index));
                    }
                }
            });


            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT);
            params.gravity = Gravity.CENTER;
            params.setMargins(0, 5, 0, 5);


            flexBoxLayout.addView(textView, params);
        }
    }


    private void displayClassInfo(List<SchoolClassInfo> classInfos, OnListenFlexLayout onListenFlexLayout) {
        FlexboxLayoutManager manager = new FlexboxLayoutManager();
        //设置主轴排列方式
        manager.setFlexDirection(FlexDirection.ROW);
        manager.setAlignItems(AlignItems.STRETCH);
        manager.setJustifyContent(JustifyContent.FLEX_START);
        //设置是否换行
        manager.setFlexWrap(FlexWrap.WRAP);

        mClassList = mDialogSwitchAddClass.findViewById(R.id.fl_class_choice);
        mClassList.setLayoutManager(manager);

        if(null == mClassRecyclerAdapter) {
            mClassRecyclerAdapter = new SchoolClassRecyclerAdapter(context, classInfos);
            mClassList.setItemAnimator(new DefaultItemAnimator());
            mClassList.setAdapter(mClassRecyclerAdapter);
        } else {
            mClassRecyclerAdapter.setData(classInfos);
            mClassRecyclerAdapter.notifyDataSetChanged();
        }
        mClassRecyclerAdapter.setOnItemClickListener(new SchoolClassRecyclerAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position, List<SchoolClassInfo> listModel) {
                if(null != onListenFlexLayout) {
                    onListenFlexLayout.onListenFlexLayout(listModel.get(position));
                }
            }
        });
    }

    private void displayClassAdminInfo(List<SchoolClassInfo> classInfos, OnListenFlexLayout onListenFlexLayout) {
        FlexboxLayoutManager manager = new FlexboxLayoutManager();
        //设置主轴排列方式
        manager.setFlexDirection(FlexDirection.ROW);
        manager.setAlignItems(AlignItems.STRETCH);
        manager.setJustifyContent(JustifyContent.FLEX_START);
        //设置是否换行
        manager.setFlexWrap(FlexWrap.WRAP);

        mClassList = mDialogSwitchAddClass.findViewById(R.id.fl_class_choice);
        mClassList.setLayoutManager(manager);

        if(null == mClassRecyclerAdapter) {
            mClassAdminRecyclerAdapter = new SchoolClassRecyclerAdapter(context, classInfos);
            mClassList.setItemAnimator(new DefaultItemAnimator());
            mClassList.setAdapter(mClassAdminRecyclerAdapter);
        } else {
            mClassAdminRecyclerAdapter.setData(classInfos);
            mClassAdminRecyclerAdapter.notifyDataSetChanged();
        }
        mClassAdminRecyclerAdapter.setOnItemClickListener(new SchoolClassRecyclerAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position, List<SchoolClassInfo> listModel) {
                if(null != onListenFlexLayout) {
                    onListenFlexLayout.onListenFlexLayout(listModel.get(position));
                }
            }
        });
    }


/*    private void displayClassAdminInfo(List<SchoolClassAdminInfo> classInfos, FlexboxLayout flexBoxLayout, OnListenFlexLayout onListenFlexLayout) {
        flexBoxLayout.removeAllViews();
        for (int i = 0; i < classInfos.size(); i++) {
            SchoolClassAdminInfo item = classInfos.get(i);
            TextView textView = new TextView(context);
            textView.setText(item.getClassName());
            textView.setTextSize(18.0f);
            textView.setTextColor(context.getResources().getColor(R.color.common_theme));
            textView.setTag(i);
            textView.setPadding(10, 0, 10, 0);
            // textView.setBackgroundResource(R.drawable.bg_round_button_selector);
            textView.setOnClickListener(new OnMultiClickListener() {
                @Override
                public void onMultiClick(View v) {
                    int index = (int)v.getTag();
                    if(null != onListenFlexLayout) {
                        onListenFlexLayout.onListenFlexLayout(classInfos.get(index));
                    }
                }
            });


            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT);
            params.gravity = Gravity.TOP;
            params.setMargins(0, 5, 0, 5);


            flexBoxLayout.addView(textView, params);
        }
    }*/


    interface OnListenFlexLayout{
        void onListenFlexLayout(Object info);
    }

    OnListenDataReq onListenDataReq;

    public void setOnListenDataReq(OnListenDataReq onListenDataReq) {
        this.onListenDataReq = onListenDataReq;
    }

    public interface OnListenDataReq{
        void onListenAreaReq(int areaType);
        void onListenAreaReq(int areaType, int id);
        void onListenSchoolGradeReq(int schoolId);
        void onListenGradeClassReq(int schoolId, int gradeId);
        void onListenGradeClassAdminReq(int schoolId, int gradeId);
        void onListenClassCoachUpdateReq(int oldId, int newId);
        void onListenClassCoachJoinReq(int id);
        void onListenClassAdminUpdateReq(int id);
    }



}
